package com.csun.cmny.provider.device.sleepcare.entity.result;

import com.csun.cmny.provider.device.sleepcare.entity.pojo.SleepCareBodyMotion;
import lombok.Data;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2019-02-23 10:32
 * @Description: the class sleep care body motion result
 */
@Data
public class SleepCareBodyMotionResult extends SleepCareBasicResult {

    private ArrayList<SleepCareBodyMotion> details = new ArrayList<SleepCareBodyMotion>();

    /**
     * 日期
     */
    private String date;

    /**
     * 是否两小时内未翻身,未翻身要给出警报
     * @return 0：未翻身需要提示，1：已翻身无提示
     */
    public int isOutofTimeNotAction(){
        if(details.size() == 0){
            return 0;
        }
        SleepCareBodyMotion bean = details.get(details.size()-1);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date lastdateTime;
        try {
            lastdateTime = sdf.parse( bean.getLastActionTime(date));
            Date now = new Date();
            long interval = (now.getTime() - lastdateTime.getTime())/1000;

            if(interval > (120 - 5) * 60){
                return 0;
            }else{
                return 1;
            }
        } catch (ParseException e) {
            e.printStackTrace();
            return 0;
        }
    }

}
